package com.neusoft.lohas.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

public class ActionUtil {
	public static String getAppendDateString(int days){
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, days);
		SimpleDateFormat sdfDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		return sdfDateFormat.format(calendar.getTime());
	}
	
	public static void writeToCrossDomainSetUtf8(HttpServletResponse response,String callbackparam,JSONObject json)
	{
		try {
			response.setCharacterEncoding("UTF-8");
			response.getWriter().write(callbackparam+"("+json.toString()+")");//(outPut.getBytes("UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("打印错误");
		}
		json = null;
		
	}
	/**
	 * 输出信息，包括跨域
	 * @param response
	 * @param appId
	 * @param callbackparam
	 * @param json
	 */
	public static void writeToCrossDomainSetUtf8(HttpServletResponse response,String appId,String callbackparam,JSONObject json)
	{
		try {
			response.setCharacterEncoding("UTF-8");
			if(appId!=null&&(appId.startsWith("00200204")||appId.startsWith("00200202"))&&callbackparam!=null&&callbackparam.length()>5)
			    response.getWriter().write(callbackparam+"("+json.toString()+")");//(outPut.getBytes("UTF-8"));
			else {
				response.getWriter().write(json.toString());//(outPut.getBytes("UTF-8"));
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("打印错误");
		}
		json = null;
	}
}
